package com.lobo.blog.service.impl;

import com.lobo.blog.entity.Blog;
import com.lobo.blog.mappers.BlogMapper;
import com.lobo.blog.service.ArchivesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @authoer:MacieSerenity
 * @createDate: 2022/10/15
 * @description:
 */
@Service
public class ArchivesServiceImpl implements ArchivesService {

    @Resource
    BlogMapper blogMapper;

    @Override
    public Map<String, List<Blog>> archivesBlog() {
        List<String> years = blogMapper.selectBlogsGroupByYear();
        Map<String, List<Blog>> map = new HashMap<>();
        for (String year : years) {
            map.put(year, blogMapper.selectBlogsByYear(year));
        }
        return map;
    }

    @Override
    public Integer getBlogCount() {
        return blogMapper.getBlogCount();
    }


}
